#pragma once
#include <pthread.h>
#include "mutex_guard.h"

class Condition{
public:
    explicit Condition(Mutex& mutex):m_mutex(mutex){
        pthread_cond_init(&m_condition, NULL);
    }

    ~Condition(){
        pthread_cond_destroy(&m_condition);
    }

    void Wait(){
        pthread_cond_wait(&m_condition, &m_mutex.m_mutex);
    }

    void Signal(){
        pthread_cond_signal(&m_condition);
    }

    void BroadCast(){
        pthread_cond_broadcast(&m_condition);
    }

private:
    Mutex& m_mutex;
    // pthread_mutex_t m_mutex;
    // only responsible for m_condition
    pthread_cond_t m_condition;
};